package com.example.zqm.git72.Adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zqm.git72.Activity.ClubDetailActivity;
import com.example.zqm.git72.JavaBean.Collection;
import com.example.zqm.git72.JavaBean.Order;
import com.example.zqm.git72.Model.ClubModel;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

//import com.example.zqm.git72.Activity.FoodActivity;

/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class MysignAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List<Order> mDataList;
    private LayoutInflater mLayoutInflater;
    //构造方法
    public MysignAdapter(Context mContext, List<Order> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_sign,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //把viewhoder数据映射到
        final Order entity = mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.sign_name.setText(entity.getName());
        viewHolder.price.setText(entity.getPrice()+"元");
        if(entity.getThumb().equals("")){
            Picasso.with(mContext).load("https://b-ssl.duitang.com/uploads/item/201409/03/20140903102455_SNNnA.png"
            )
                    .resize(50,50).into(viewHolder.sign_pic);
        }else{
            String picUrl = "http://172.24.10.175/workout/Uploads/" + entity.getThumb();
            Picasso.with(mContext).load(picUrl.toString())
                    .resize(50,50).into(viewHolder.sign_pic);
        }

        //Context上下文在很多Android Api中都是必须的,图片网络加载地址,想进行图片展示的ImageView


    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView sign_pic;
        TextView sign_name,price;
        //构造方法
        public ViewHolder(View itemView) {
            super(itemView);
            sign_name = (TextView) itemView.findViewById(R.id.sign_name);
            sign_pic = (ImageView) itemView.findViewById(R.id.sign_pic);
            price=(TextView) itemView.findViewById(R.id.price);

        }
    }

}
